package com.example.studentdemo4.service;

import com.example.studentdemo4.pojo.Student;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/students")
public class StudentContorller {
    private final StudentRepository studentRepository;

    public StudentContorller(StudentRepository studentRepository) {
        this.studentRepository = studentRepository;
    }

    @GetMapping
    public List<Student> getAllStudents() {
        return studentRepository.findAll();
    }

    @PostMapping
    public Student createStudent(@RequestBody Student student) {
        return studentRepository.save(student);
    }

    // 你可以根据需要添加更多REST API方法，如更新和删除学生信息

}
